
***** PANEL A: 

use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear



drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m




capture drop ratio
gen ratio=kurtosis/freq


gen d_dieselr_pos=.
replace d_dieselr_pos=d_dieselr if d_dieselr>=0 & d_dieselr!=.
replace d_dieselr_pos=0 if d_dieselr<0 & d_dieselr!=.

gen d_dieselr_neg=.
replace d_dieselr_neg=d_dieselr if d_dieselr<0 & d_dieselr!=.
replace d_dieselr_neg=0 if d_dieselr>=0 & d_dieselr!=.

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff4_reg
capture drop coeff5_reg
capture drop coeff6_reg
capture drop coeff7_reg
capture drop coeff8_reg
capture drop coeff9_reg
capture drop coeff10_reg



capture drop coeff_c_reg


capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop se_coeff4_reg
capture drop se_coeff5_reg
capture drop se_coeff6_reg
capture drop se_coeff7_reg
capture drop se_coeff8_reg
capture drop se_coeff9_reg
capture drop se_coeff10_reg

capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff4_reg=.
gen coeff5_reg=.
gen coeff6_reg=.
gen coeff7_reg=.
gen coeff8_reg=.
gen coeff9_reg=.
gen coeff10_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen se_coeff4_reg=.
gen se_coeff5_reg=.
gen se_coeff6_reg=.
gen se_coeff7_reg=.
gen se_coeff8_reg=.
gen se_coeff9_reg=.
gen se_coeff10_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.




**** Panel A: lines 3-4, H=30

****** H=30 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr_pos##(c.ratio c.mean c.sd c.skewness) c.d_dieselr_neg##(c.ratio c.mean c.sd c.skewness) ///
c.local_shock10##(c.ratio c.mean c.sd c.skewness) /// 
c.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
 c.l.d_dieselr_pos##(c.ratio c.mean c.sd c.skewness) ///
 c.l2.d_dieselr_pos##(c.ratio c.mean c.sd c.skewness) ///
 c.l3.d_dieselr_pos##(c.ratio c.mean c.sd c.skewness) ///
 c.l4.d_dieselr_pos##(c.ratio c.mean c.sd c.skewness) /// 
 c.l5.d_dieselr_pos##(c.ratio c.mean c.sd c.skewness) ///
 c.l.d_dieselr_neg##(c.ratio c.mean c.sd c.skewness) ///
 c.l2.d_dieselr_neg##(c.ratio c.mean c.sd c.skewness) ///
 c.l3.d_dieselr_neg##(c.ratio c.mean c.sd c.skewness) ///
 c.l4.d_dieselr_neg##(c.ratio c.mean c.sd c.skewness) /// 
 c.l5.d_dieselr_neg##(c.ratio c.mean c.sd c.skewness ) ///
		c.l.local_shock10##(c.ratio c.mean c.sd c.skewness)  /// 
		c.l2.local_shock10##(c.ratio c.mean c.sd c.skewness) /// 
		c.l3.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
		c.l4.local_shock10##(c.ratio c.mean c.sd c.skewness) /// 
		c.l5.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
	c.l.m_dprix##(c.ratio c.mean c.sd c.skewness)  /// 
	c.l2.m_dprix##(c.ratio c.mean c.sd c.skewness) /// 
	c.l3.m_dprix##(c.ratio c.mean c.sd c.skewness) /// 
	c.l4.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
	c.l5.m_dprix##(c.ratio c.mean c.sd c.skewness) , absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr_pos] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr_pos#c.ratio] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr_pos#c.mean] if num_obs==`i'
replace coeff4_reg=_b[c.d_dieselr_pos#c.sd] if num_obs==`i'
replace coeff5_reg=_b[c.d_dieselr_pos#c.skewness] if num_obs==`i'
replace coeff6_reg=_b[d_dieselr_neg] if num_obs==`i'
replace coeff7_reg=_b[c.d_dieselr_neg#c.ratio] if num_obs==`i'
replace coeff8_reg=_b[c.d_dieselr_neg#c.mean] if num_obs==`i'
replace coeff9_reg=_b[c.d_dieselr_neg#c.sd] if num_obs==`i'
replace coeff10_reg=_b[c.d_dieselr_neg#c.skewness] if num_obs==`i'


replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr_pos] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr_pos#c.ratio] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr_pos#c.mean] if num_obs==`i'
replace se_coeff4_reg=_se[c.d_dieselr_pos#c.sd] if num_obs==`i'
replace se_coeff5_reg=_se[c.d_dieselr_pos#c.skewness] if num_obs==`i'
replace se_coeff6_reg=_se[d_dieselr_neg] if num_obs==`i'
replace se_coeff7_reg=_se[c.d_dieselr_neg#c.ratio] if num_obs==`i'
replace se_coeff8_reg=_se[c.d_dieselr_neg#c.mean] if num_obs==`i'
replace se_coeff9_reg=_se[c.d_dieselr_neg#c.sd] if num_obs==`i'
replace se_coeff10_reg=_se[c.d_dieselr_neg#c.skewness] if num_obs==`i'

replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff* r2 r2_a  se_coeff* df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==30
save "$path\Graphs_Tables\TableD3_constrainedpanel_PanelA_asym.dta", replace
restore 

}


*** Panel B: Size of the shock


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear


drop if prix_ht==.
drop j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m




capture drop ratio
gen ratio=kurtosis/freq

gen d_dieselr_lessmean=.
replace d_dieselr_lessmean=d_dieselr if abs(d_dieselr)<=0.010 & d_dieselr!=.
replace d_dieselr_lessmean=0 if abs(d_dieselr)>0.010 & d_dieselr!=.

gen d_dieselr_meantomax=.
replace d_dieselr_meantomax=d_dieselr if abs(d_dieselr)>0.010 & d_dieselr!=.
replace d_dieselr_meantomax=0 if abs(d_dieselr)<=0.010 & d_dieselr!=.

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff4_reg
capture drop coeff5_reg
capture drop coeff6_reg
capture drop coeff7_reg
capture drop coeff8_reg
capture drop coeff9_reg
capture drop coeff10_reg



capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop se_coeff4_reg
capture drop se_coeff5_reg
capture drop se_coeff6_reg
capture drop se_coeff7_reg
capture drop se_coeff8_reg
capture drop se_coeff9_reg
capture drop se_coeff10_reg

capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff4_reg=.
gen coeff5_reg=.
gen coeff6_reg=.
gen coeff7_reg=.
gen coeff8_reg=.
gen coeff9_reg=.
gen coeff10_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen se_coeff4_reg=.
gen se_coeff5_reg=.
gen se_coeff6_reg=.
gen se_coeff7_reg=.
gen se_coeff8_reg=.
gen se_coeff9_reg=.
gen se_coeff10_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.




**** Panel A: lines 3-4, H=30

****** H=30 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr_lessmean##(c.ratio c.mean c.sd c.skewness) c.d_dieselr_meantomax##(c.ratio c.mean c.sd c.skewness) ///
c.local_shock10##(c.ratio c.mean c.sd c.skewness) /// 
c.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
 c.l.d_dieselr_lessmean##(c.ratio c.mean c.sd c.skewness) ///
 c.l2.d_dieselr_lessmean##(c.ratio c.mean c.sd c.skewness) ///
 c.l3.d_dieselr_lessmean##(c.ratio c.mean c.sd c.skewness) ///
 c.l4.d_dieselr_lessmean##(c.ratio c.mean c.sd c.skewness) /// 
 c.l5.d_dieselr_lessmean##(c.ratio c.mean c.sd c.skewness) ///
 c.l.d_dieselr_meantomax##(c.ratio c.mean c.sd c.skewness) ///
 c.l2.d_dieselr_meantomax##(c.ratio c.mean c.sd c.skewness) ///
 c.l3.d_dieselr_meantomax##(c.ratio c.mean c.sd c.skewness) ///
 c.l4.d_dieselr_meantomax##(c.ratio c.mean c.sd c.skewness) /// 
 c.l5.d_dieselr_meantomax##(c.ratio c.mean c.sd c.skewness ) ///
		c.l.local_shock10##(c.ratio c.mean c.sd c.skewness)  /// 
		c.l2.local_shock10##(c.ratio c.mean c.sd c.skewness) /// 
		c.l3.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
		c.l4.local_shock10##(c.ratio c.mean c.sd c.skewness) /// 
		c.l5.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
	c.l.m_dprix##(c.ratio c.mean c.sd c.skewness)  /// 
	c.l2.m_dprix##(c.ratio c.mean c.sd c.skewness) /// 
	c.l3.m_dprix##(c.ratio c.mean c.sd c.skewness) /// 
	c.l4.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
	c.l5.m_dprix##(c.ratio c.mean c.sd c.skewness) if abs(d_dieselr)<0.059, absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr_lessmean] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr_lessmean#c.ratio] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr_lessmean#c.mean] if num_obs==`i'
replace coeff4_reg=_b[c.d_dieselr_lessmean#c.sd] if num_obs==`i'
replace coeff5_reg=_b[c.d_dieselr_lessmean#c.skewness] if num_obs==`i'
replace coeff6_reg=_b[d_dieselr_meantomax] if num_obs==`i'
replace coeff7_reg=_b[c.d_dieselr_meantomax#c.ratio] if num_obs==`i'
replace coeff8_reg=_b[c.d_dieselr_meantomax#c.mean] if num_obs==`i'
replace coeff9_reg=_b[c.d_dieselr_meantomax#c.sd] if num_obs==`i'
replace coeff10_reg=_b[c.d_dieselr_meantomax#c.skewness] if num_obs==`i'


replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr_lessmean] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr_lessmean#c.ratio] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr_lessmean#c.mean] if num_obs==`i'
replace se_coeff4_reg=_se[c.d_dieselr_lessmean#c.sd] if num_obs==`i'
replace se_coeff5_reg=_se[c.d_dieselr_lessmean#c.skewness] if num_obs==`i'
replace se_coeff6_reg=_se[d_dieselr_meantomax] if num_obs==`i'
replace se_coeff7_reg=_se[c.d_dieselr_meantomax#c.ratio] if num_obs==`i'
replace se_coeff8_reg=_se[c.d_dieselr_meantomax#c.mean] if num_obs==`i'
replace se_coeff9_reg=_se[c.d_dieselr_meantomax#c.sd] if num_obs==`i'
replace se_coeff10_reg=_se[c.d_dieselr_meantomax#c.skewness] if num_obs==`i'

replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff* r2 r2_a  se_coeff* df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==30
save "$path\Graphs_Tables\TableD3_constrainedpanel_PanelB_size.dta", replace
restore 

}






**** Panel C: Moving Average



use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear


drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)

drop diesel_rotterdam_euro resid_movav_diesel dprix1 

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m


******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff4_reg
capture drop coeff5_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop se_coeff4_reg
capture drop se_coeff5_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff4_reg=.
gen coeff5_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen se_coeff4_reg=.
gen se_coeff5_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.




capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_MA
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_MA
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.local_shock10##(c.ratio c.mean c.sd c.skewness) c.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
 c.l.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l2.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l3.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
 c.l4.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l5.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
		c.l.local_shock10##(c.ratio c.mean c.sd c.skewness)  c.l2.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l3.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
		c.l4.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l5.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
	c.l.m_dprix##(c.ratio c.mean c.sd c.skewness)  c.l2.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l3.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l4.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
	c.l5.m_dprix##(c.ratio c.mean c.sd c.skewness), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.mean] if num_obs==`i'
replace coeff4_reg=_b[c.d_dieselr#c.sd] if num_obs==`i'
replace coeff5_reg=_b[c.d_dieselr#c.skewness] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.mean] if num_obs==`i'
replace se_coeff4_reg=_se[c.d_dieselr#c.sd] if num_obs==`i'
replace se_coeff5_reg=_se[c.d_dieselr#c.skewness] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'



preserve
keep coeff1_reg coeff2_reg coeff3_reg coeff4_reg coeff5_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg se_coeff4_reg se_coeff5_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==30
save "$path\Graphs_Tables\TableD3_constrainedpanel_PanelC_MA.dta", replace
restore 
}


**** Panel D: Brent


**** H= 24
use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear
merge m:1 daten using "$path\Intermediary Data\data_brent.dta"
drop _m
drop if prix_ht==.
drop  j j3

drop diesel_rotterdam_euro resid_movav_diesel dprix1 
xtset id daten
gen d_brenteuro=ln(brenteuro)-ln(l1.brenteuro)

capture drop d_dieselr
gen d_dieselr=d_brenteuro

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff4_reg
capture drop coeff5_reg
capture drop coeff_c_reg


capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop se_coeff4_reg
capture drop se_coeff5_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff4_reg=.
gen coeff5_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen se_coeff4_reg=.
gen se_coeff5_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.




***** H=24 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/23 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_brentonly24
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 24 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_brentonly24
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.local_shock10##(c.ratio c.mean c.sd c.skewness) c.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
 c.l.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l2.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l3.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
 c.l4.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l5.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
		c.l.local_shock10##(c.ratio c.mean c.sd c.skewness)  c.l2.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l3.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
		c.l4.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l5.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
	c.l.m_dprix##(c.ratio c.mean c.sd c.skewness)  c.l2.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l3.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l4.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
	c.l5.m_dprix##(c.ratio c.mean c.sd c.skewness), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.mean] if num_obs==`i'
replace coeff4_reg=_b[c.d_dieselr#c.sd] if num_obs==`i'
replace coeff5_reg=_b[c.d_dieselr#c.skewness] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.mean] if num_obs==`i'
replace se_coeff4_reg=_se[c.d_dieselr#c.sd] if num_obs==`i'
replace se_coeff5_reg=_se[c.d_dieselr#c.skewness] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg coeff3_reg coeff4_reg coeff5_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg se_coeff4_reg se_coeff5_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==24
save "$path\Graphs_Tables\TableD3_constrainedpanel_PanelD_brentonly.dta", replace
restore
}




***** h=30

use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear
merge m:1 daten using "$path\Intermediary Data\data_brent.dta"
drop _m
drop if prix_ht==.
drop j j3

drop diesel_rotterdam_euro resid_movav_diesel dprix1 
xtset id daten
gen d_brenteuro=ln(brenteuro)-ln(l1.brenteuro)

capture drop d_dieselr
gen d_dieselr=d_brenteuro

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m

******** RATIO
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff4_reg
capture drop coeff5_reg
capture drop coeff_c_reg

capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop se_coeff4_reg
capture drop se_coeff5_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff4_reg=.
gen coeff5_reg=.
gen coeff_c_reg=.

gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen se_coeff4_reg=.
gen se_coeff5_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.


***** H=30 ****
capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_brentonly
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect_brentonly
replace f_prix_ht=f_prix_ht_temp+f_prix_ht



areg f_prix_ht c.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.local_shock10##(c.ratio c.mean c.sd c.skewness) c.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
 c.l.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l2.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l3.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
 c.l4.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l5.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
		c.l.local_shock10##(c.ratio c.mean c.sd c.skewness)  c.l2.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l3.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
		c.l4.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l5.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
	c.l.m_dprix##(c.ratio c.mean c.sd c.skewness)  c.l2.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l3.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l4.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
	c.l5.m_dprix##(c.ratio c.mean c.sd c.skewness), absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.mean] if num_obs==`i'
replace coeff4_reg=_b[c.d_dieselr#c.sd] if num_obs==`i'
replace coeff5_reg=_b[c.d_dieselr#c.skewness] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'

replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.mean] if num_obs==`i'
replace se_coeff4_reg=_se[c.d_dieselr#c.sd] if num_obs==`i'
replace se_coeff5_reg=_se[c.d_dieselr#c.skewness] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg coeff3_reg coeff4_reg coeff5_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg se_coeff4_reg se_coeff5_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==30
save "$path\Graphs_Tables\TableD3_constrainedpanel_PanelD_brentonly2.dta", replace
restore
}





**** Panel E: no extreme values


use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

*gen t=(prix_ht==.)
drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m


capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff3_reg
capture drop coeff4_reg
capture drop coeff5_reg
capture drop coeff_c_reg
capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop se_coeff3_reg
capture drop se_coeff4_reg
capture drop se_coeff5_reg
capture drop df_reg
capture drop r2
capture drop r2_a


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff3_reg=.
gen coeff4_reg=.
gen coeff5_reg=.
gen coeff_c_reg=.
gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen se_coeff3_reg=.
gen se_coeff4_reg=.
gen se_coeff5_reg=.
gen df_reg=.

gen r2=.
gen r2_a=.






capture drop f_prix_ht 
capture drop f_prix_ht_temp
gen f_prix_ht=0

foreach i of numlist 1/29 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


foreach i of numlist 30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht

areg f_prix_ht c.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.local_shock10##(c.ratio c.mean c.sd c.skewness) c.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
 c.l.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l2.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l3.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
 c.l4.d_dieselr##(c.ratio c.mean c.sd c.skewness) c.l5.d_dieselr##(c.ratio c.mean c.sd c.skewness) ///
		c.l.local_shock10##(c.ratio c.mean c.sd c.skewness)  c.l2.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l3.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
		c.l4.local_shock10##(c.ratio c.mean c.sd c.skewness) c.l5.local_shock10##(c.ratio c.mean c.sd c.skewness) ///
	c.l.m_dprix##(c.ratio c.mean c.sd c.skewness)  c.l2.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l3.m_dprix##(c.ratio c.mean c.sd c.skewness) c.l4.m_dprix##(c.ratio c.mean c.sd c.skewness) ///
	c.l5.m_dprix##(c.ratio c.mean c.sd c.skewness) if abs(d_dieselr)<0.059, absorb(id) vce(cluster daten)

	
	replace r2=e(r2)
replace r2_a=e(r2_a)
	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff3_reg=_b[c.d_dieselr#c.mean] if num_obs==`i'
replace coeff4_reg=_b[c.d_dieselr#c.sd] if num_obs==`i'
replace coeff5_reg=_b[c.d_dieselr#c.skewness] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'

replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace se_coeff3_reg=_se[c.d_dieselr#c.mean] if num_obs==`i'
replace se_coeff4_reg=_se[c.d_dieselr#c.sd] if num_obs==`i'
replace se_coeff5_reg=_se[c.d_dieselr#c.skewness] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'

preserve
keep coeff1_reg coeff2_reg coeff3_reg coeff4_reg coeff5_reg r2 r2_a  se_coeff1_reg se_coeff2_reg se_coeff3_reg se_coeff4_reg se_coeff5_reg df_reg num_obs
gen name="`i'"
gen charact="constrained"
keep if num_obs==30
save "$path\Graphs_Tables\TableD3_constrainedpanel_PanelE_noextremevalues.dta", replace
restore 
}



**** Append data ***

clear

use  "$path\Graphs_Tables\TableD3_constrainedpanel_PanelA_asym.dta", replace
append using "$path\Graphs_Tables\TableD3_constrainedpanel_PanelB_size.dta"
append using "$path\Graphs_Tables\TableD3_constrainedpanel_PanelC_MA.dta"
append using "$path\Graphs_Tables\TableD3_constrainedpanel_PanelD_brentonly.dta"
append using "$path\Graphs_Tables\TableD3_constrainedpanel_PanelD_brentonly2.dta"
append using "$path\Graphs_Tables\TableD3_constrainedpanel_PanelE_noextremevalues.dta"


gen id_col=_n

xpose, clear

drop if _n==1


gen col1=.
gen col2=.
gen col3=.
gen col4=.
gen col5=.
gen col6=.

replace col1=v1[1] if _n==1
replace col1=v1[6] if _n==3
replace col1=v2[1] if _n==5
replace col1=v2[6] if _n==7
replace col1=v3[1] if _n==9
replace col1=v4[1] if _n==11
replace col1=v5[1] if _n==13
replace col1=v6[1] if _n==15

replace col1=v1[12] if _n==2
replace col1=v1[17] if _n==4
replace col1=v2[12] if _n==6
replace col1=v2[17] if _n==8
replace col1=v3[12] if _n==10
replace col1=v4[12] if _n==12
replace col1=v5[12] if _n==14
replace col1=v6[12] if _n==16


replace col2=v1[2] if _n==1
replace col2=v1[7] if _n==3
replace col2=v2[2] if _n==5
replace col2=v2[7] if _n==7
replace col2=v3[2] if _n==9
replace col2=v4[2] if _n==11
replace col2=v5[2] if _n==13
replace col2=v6[2] if _n==15


replace col2=v1[13] if _n==2
replace col2=v1[18] if _n==4
replace col2=v2[13] if _n==6
replace col2=v2[18] if _n==8
replace col2=v3[13] if _n==10
replace col2=v4[13] if _n==12
replace col2=v5[13] if _n==14
replace col2=v6[13] if _n==16



replace col3=v1[3]/100 if _n==1
replace col3=v1[8]/100 if _n==3
replace col3=v2[3]/100 if _n==5
replace col3=v2[8]/100 if _n==7
replace col3=v3[3]/100 if _n==9
replace col3=v4[3]/100 if _n==11
replace col3=v5[3]/100 if _n==13
replace col3=v6[3]/100 if _n==15


replace col3=v1[14]/100 if _n==2
replace col3=v1[19]/100 if _n==4
replace col3=v2[14]/100 if _n==6
replace col3=v2[19]/100 if _n==8
replace col3=v3[14]/100 if _n==10
replace col3=v4[14]/100 if _n==12
replace col3=v5[14]/100 if _n==14
replace col3=v6[14]/100 if _n==16


replace col4=v1[4] if _n==1
replace col4=v1[9] if _n==3
replace col4=v2[4] if _n==5
replace col4=v2[9] if _n==7
replace col4=v3[4] if _n==9
replace col4=v4[4] if _n==11
replace col4=v5[4] if _n==13
replace col4=v6[4] if _n==15


replace col4=v1[15] if _n==2
replace col4=v1[20] if _n==4
replace col4=v2[15] if _n==6
replace col4=v2[20] if _n==8
replace col4=v3[15] if _n==10
replace col4=v4[15] if _n==12
replace col4=v5[15] if _n==14
replace col4=v6[15] if _n==16


replace col5=v1[5] if _n==1
replace col5=v1[10] if _n==3
replace col5=v2[5] if _n==5
replace col5=v2[10] if _n==7
replace col5=v3[5] if _n==9
replace col5=v4[5] if _n==11
replace col5=v5[5] if _n==13
replace col5=v6[5] if _n==15

replace col5=v1[16] if _n==2
replace col5=v1[21] if _n==4
replace col5=v2[16] if _n==6
replace col5=v2[21] if _n==8
replace col5=v3[16] if _n==10
replace col5=v4[16] if _n==12
replace col5=v5[16] if _n==14
replace col5=v6[16] if _n==16



replace col6=v1[23] if _n==1
replace col6=v2[23] if _n==5
replace col6=v3[23] if _n==9
replace col6=v4[23] if _n==11
replace col6=v5[23] if _n==13
replace col6=v6[23] if _n==15


keep col*

gen Panel="Panel A: Asymmetric shock" if _n==1
replace Panel="Panel B: Size of the shock" if _n==5
replace Panel="Panel C: Moving average shock" if _n==9
replace Panel="Panel D: Brent shock" if _n==11
replace Panel="Panel E: Rotterdam shock - Excl. 1%-extreme values" if _n==15


gen Var="Positive, H=30" if _n==1
replace Var="Negative, H=30" if _n==3
replace Var="Below median, H=30" if _n==5
replace Var="Above median, H=30" if _n==7
replace Var="H=30 days" if _n==9
replace Var="H=24 days" if _n==11
replace Var="H=30 days" if _n==13
replace Var="H=30 days" if _n==15


gen tstatcol1=.
gen tstatcol2=.
gen tstatcol3=.
gen tstatcol4=.
gen tstatcol5=.
gen tstatcol6=.


foreach i in 1 3 5 7 9 11 13 15{
replace tstatcol1=col1[`i']/col1[`i'+1] if _n==`i'
replace tstatcol2=col2[`i']/col2[`i'+1] if _n==`i'
replace tstatcol3=col3[`i']/col3[`i'+1] if _n==`i' 
replace tstatcol4=col4[`i']/col4[`i'+1] if _n==`i'
replace tstatcol5=col5[`i']/col5[`i'+1] if _n==`i'
}

gen starscol1=""
gen starscol2=""
gen starscol3=""
gen starscol4=""
gen starscol5=""

foreach i in 1 2 3 4 5 {
replace starscol`i'="***" if abs(tstatcol`i')>=2.58 & tstatcol`i'!=.
replace starscol`i'="**" if abs(tstatcol`i')<2.58 & abs(tstatcol`i')>=1.96 & tstatcol`i'!=.
replace starscol`i'="*" if abs(tstatcol`i')<1.96 & abs(tstatcol`i')>=1.64 & tstatcol`i'!=.
}

drop tstat*
rename col* coltemp*

foreach i in 1 2 3 4 5 {
replace coltemp`i'=round(coltemp`i', 0.001)
tostring coltemp`i', gen(coltempbis`i') force format("%9.3f")  
egen col`i'=concat(coltempbis`i' starscol`i')
}


rename col1 Shock
rename col2 ShockxRatio
rename col3 ShockxMean
rename col4 ShockxSD
rename col5 ShockxSkew
rename coltemp6 R2


keep Panel Var Shock ShockxRatio  ShockxMean ShockxSD ShockxSkew R2
order Panel Var Shock  ShockxRatio ShockxMean ShockxSD ShockxSkew R2
replace R2=round(R2, 0.001)
format %9.3f  R2
drop if _n>16


save "$path\Graphs_Tables\TableD3_edited.dta", replace



